﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class LoginTest : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {   
        if(txtName.Text==""&&txtPwd.Text=="")
              { Response.Write("用户名或密码不为空!"); }
        else {
        string userName = txtName.Text;
        string userPwd =txtPwd.Text;
        string ConnStr = "server=.\\sqlexpress; database=Student; User ID=sa;Password=sa";
        using (SqlConnection conn = new SqlConnection(ConnStr))
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandText = "Select * from studentinfo where UserName='" + userName + "'and UserPwd='" + userPwd + "'";
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                dr.Close();
                Response.Redirect("Default.aspx");
                //Response.Write("登陆成功!");
            }
            else
            {
                Response.Write("用户名或密码错误");
            }
        }
      }
    }
}